package com.zjj.learn.designmodel.work.composite;

import java.util.ArrayList;
import java.util.List;

public class Directory implements FileSystemComponent {

    private String name;

    private List<FileSystemComponent> components;

    public Directory(String name) {
        this.name = name;
        this.components = new ArrayList<>();
    }


    public void addComponents(FileSystemComponent component) {
        this.components.add(component);
    }

    public void remove(FileSystemComponent component) {
        this.components.remove(component);
    }

    @Override
    public void display() {
        System.out.println(this.name + " 文件夹");
        if (!this.components.isEmpty()) {
            //依次展示每一个文件组件
            for (FileSystemComponent component : this.components) {
                component.display();
            }
        }
    }
}
